package com.doudou.collection.infrastructure.core.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

/**
 * @ClassName RedisConfig<br>
 * @Description Redis配置类<br>
 * @Author 李浩文<br>
 * @Date 2023/6/30 11:37<br>
 * @Version 1.0<br>
 */
@Slf4j
@Configuration
public class RedisConfig {

    public RedisConfig() {
        log.debug("创建配置类对象：RedisConfig");
    }

    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(RedisSerializer.string());
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
